package com.cwj;

/**
 * @author chenwujie
 * @date 2020-12-10 09:15
 */
public class UPCCacheLineTest {
    public static void main(String[] args) {
        long l = System.nanoTime();
        int[][] array = new int[1024][64 * 1024];

        // 横向遍历
        for(int i = 0; i < 1024; i ++){
            for(int j = 0; j < 64 * 1024; j ++) {
                array[i][j]++;
            }
        }
        long l2 = System.nanoTime();

        // 纵向遍历
        for(int i = 0; i < 64 * 1024; i ++){
            for(int j = 0; j < 1024; j ++){
                array[j][i] ++;
            }
        }
        long l3 = System.nanoTime();
        System.out.println(l2 - l);
        System.out.println(l3 - l2);
    }

    private static class Data{
        private volatile long l;
        public Data(long l){
            this.l = l;
        }
    }
}
